'''
Created on Oct 30, 2014

@author: azhelezny
'''


class FastaRecord:
    def __init__(self, name , dna):
        self.name = name
        self.dna = dna


inputFile = open("D:\\fasta.input")
lines = []
fileString = inputFile.readline()
while 1:
    if(not fileString):
        break
    rName = fileString.replace("\n", "").replace(">", "")
    temp = ""
    while 1:
        fileString = inputFile.readline().replace("\n", "")
        if(not fileString or fileString.count(">") != 0):
            break
        temp += fileString
    lines.append(FastaRecord(rName, temp))
inputFile.close()

for i in range(0, len(lines)):
    iLineSuffics = lines[i].dna[::-1][:3][::-1]
    for j in range(0, len(lines)):
        if (i == j):
            continue
        jLinePrefix = lines[j].dna[:3]
        if (iLineSuffics == jLinePrefix):
            print(lines[i].name + " " + lines[j].name)
        
